package com.flowerplus.store.common.data.utils.ui;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;

/**
 * Created by z on.
 * Des:
 * Date: 2017/3/13
 */

public class DialogUtil {

    public static AlertDialog createDialog(Activity activity, String title, String message, boolean iscancelabe
            , String button1Str, Dialog.OnClickListener button1Listener,
                                           String button2Str, Dialog.OnClickListener button2Listener) {

        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);
        }
        AlertDialog alertDialog = builder
                .setCancelable(iscancelabe)
                .setMessage(message)
                .setNegativeButton(button1Str, button1Listener)
                .setPositiveButton(button2Str, button2Listener).create();
        alertDialog.show();
        return alertDialog;
    }

    public static AlertDialog createDialogNoShow(Activity activity, String title, String message, boolean isCancelable
            , String button1Str, Dialog.OnClickListener button1Listener,
                                                 String button2Str, Dialog.OnClickListener button2Listener) {
        AlertDialog alertDialog = new AlertDialog.Builder(activity)
                .setCancelable(isCancelable)
                .setTitle(title)
                .setMessage(message)
                .setNegativeButton(button1Str, button1Listener)
                .setPositiveButton(button2Str, button2Listener).create();
        return alertDialog;
    }

    public static AlertDialog createDialog(Activity activity, String title, String message,
                                           String button2Str, Dialog.OnClickListener button2Listener) {
        return createDialog(activity, title, message, false, "取消", null, button2Str, button2Listener);
    }

    public static AlertDialog createDialog(Activity activity, String message,
                                           String button2Str, Dialog.OnClickListener button2Listener) {
        return createDialog(activity, "", message, false, "取消", null, button2Str, button2Listener);
    }

    public static AlertDialog createDialogNoShow(Activity activity, String title, String message,
                                                 String button2Str, Dialog.OnClickListener button2Listener) {
        return createDialogNoShow(activity, title, message, false, "取消", null, button2Str, button2Listener);
    }

    public static AlertDialog createNotifyDialog(Activity activity, String title, String message,
                                                 String buttonStr, Dialog.OnClickListener button2Listener) {
        return new AlertDialog.Builder(activity)
                .setTitle(title)
                .setMessage(message)
                .setNegativeButton(buttonStr, button2Listener).create();
    }

    public static AlertDialog createNotifyDialog(Activity activity, String title, String message,
                                                 String buttonStr) {
        return createNotifyDialog(activity, title, message, buttonStr, null);
    }

    public static AlertDialog createDialog(Activity activity, String title, String message, boolean iscancelabe, View v
            , String button1Str, Dialog.OnClickListener button1Listener,
                                           String button2Str, Dialog.OnClickListener button2Listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity)
                .setCancelable(iscancelabe);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);
        }
        AlertDialog alertDialog = builder
                .setCancelable(iscancelabe)
                .setView(v)
                .setMessage(message)
                .setNegativeButton(button1Str, button1Listener)
                .setPositiveButton(button2Str, button2Listener).create();
        alertDialog.show();
        return alertDialog;
    }

    public static AlertDialog createDialog(Activity activity, String title, String message, View v,
                                           String button2Str, Dialog.OnClickListener button2Listener) {
        return createDialog(activity, title, message, false, v, "取消", null, button2Str, button2Listener);
    }

    public static AlertDialog createDialog(Activity activity, String title, View v,
                                           String button2Str, Dialog.OnClickListener button2Listener) {
        return createDialog(activity, title, "", false, v, "取消", null, button2Str, button2Listener);
    }

    public static AlertDialog createDialog(Activity activity, String title, String message, String button1Str, Dialog.OnClickListener button1Listener
            , String button2Str, Dialog.OnClickListener button2Listener,
                                           String button3Str, Dialog.OnClickListener button3Listener) {
        return new AlertDialog.Builder(activity)
                .setCancelable(false)
                .setTitle(title)
                .setMessage(message)
                .setNegativeButton(button1Str, button1Listener)
                .setNeutralButton(button2Str, button2Listener)
                .setPositiveButton(button3Str, button3Listener).create();
    }


    public static ProgressDialog createProgressDialog(Activity activity, String title, String message, boolean cancelable) {
        ProgressDialog progressDialog = new ProgressDialog(activity);
        if (!TextUtils.isEmpty(title)) {
            progressDialog.setTitle(title);
        }
        progressDialog.setMessage(message);
        progressDialog.setCancelable(cancelable);
        return progressDialog;

    }

    public static ProgressDialog createProgressDialog(Activity activity) {
        return createProgressDialog(activity, "", "请稍候...", false);
    }

    public static ProgressDialog createProgressDialog(Activity activity, String content) {
        return createProgressDialog(activity, "", content, false);
    }

    public static AlertDialog createListDialog(Activity activity, String title, String[] strings, DialogInterface.OnClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity).setItems(strings, listener);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);
        }
        return builder.create();
    }

    public static AlertDialog createListDialog(Activity activity, String[] strings, DialogInterface.OnClickListener listener) {
        return createListDialog(activity, "", strings, listener);
    }

    public static AlertDialog createListDialog(Activity activity, String[] strings) {
        return createListDialog(activity, "", strings, null);
    }

    public static AlertDialog createSingleChoiceItemsDialog(Activity act, String title,
                                                            CharSequence[] items, int checkedItem, final DialogInterface.OnClickListener listener) {
        return new AlertDialog.Builder(act)
                .setTitle(title)
                .setSingleChoiceItems(items, checkedItem, listener).create();

    }

    public static void show(ProgressDialog pd) {
        if (pd != null && !pd.isShowing()) {
            pd.show();
        }
    }

    public static void hide(ProgressDialog pd) {
        if (pd != null && pd.isShowing()) {
            pd.dismiss();
        }
    }



}
